package com.mlk.car.api;

import com.mlk.core.util.ServerResponse;
import com.mlk.engSystem.po.EngSysEmp;
import com.mlk.engSystem.service.EngSysEmpService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 车辆的API
 */
@RestController
@RequestMapping("/api/car")
public class EngCarAPI {

    @Resource
    private EngSysEmpService engSysEmpService;

    /**
     * 获取车辆信息
     * @return
     */
    @GetMapping("getCarList")
    public ServerResponse getCarList(String openId){
        // 通过openId 获取emp对象
        EngSysEmp emp = this.engSysEmpService.getEmpByOpenId(openId);

        if(emp.getDepositId() == null){
            ServerResponse.fail("该员工没有分配暂存区");
        }
        return ServerResponse.ok(this.engSysEmpService.getAllCanUseCar(emp.getId()));
    }

    /**
     * 分配车辆信息
     *
     * 参数  openId carId
     * @return
     */
    @RequestMapping("allocateCar")
    public ServerResponse allocateCar(EngSysEmp emp){
        return  this.engSysEmpService.allocateCar(emp);
    }

}
